"""
進入爱逛卖家版
"""
import time

import yaml
from uiautomator2 import xpath


from page_object.guang_page import GuangPage
from resource.path_info import *

"""
消息
"""
class MessagePage(GuangPage):
    """
    查看消息-点赞
    """
    def check_message_zan(self, d):
        print("check_message_zan")
        d.xpath(message_to_like_xpath).wait(timeout=3.0)
        d.xpath(message_to_like_xpath).click()
        d.xpath(message_like_header_xpath).wait(timeout=3.0)
        if d.xpath(message_like_header_xpath).exists:
            print("into like detail successfully")
        else:
            raise Exception("into like detail failed")
        if d.xpath(message_like_info_xpath).exists:
            print("into like detail successfully")
        else:
            raise Exception("into like detail failed")
        if d.xpath(message_like_name_xpath).exists:
            print("into like detail successfully")
        else:
            raise Exception("into like detail failed")
        if d.xpath(message_like_time_xpath).exists:
            print("into like detail successfully")
        else:
            raise Exception("into like detail failed")
        if d.xpath(message_like_video_header_xpath).exists:
            print("into like detail successfully")
        else:
            raise Exception("into like detail failed")
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-评论
    """
    def check_message_comment(self, d):
        print("check_message_comment")
        d.xpath(message_to_comment_xpath).wait(timeout=3.0)
        d.xpath(message_to_comment_xpath).click()
        d.xpath(message_comment_header_xpath).wait(timeout=3.0)
        if d.xpath(message_comment_header_xpath).exists:
            print("into message_comment_header_xpath detail successfully")
        else:
            raise Exception("into message_comment_header_xpath detail failed")
        if d.xpath(message_comment_info_xpath).exists:
            print("into message_comment_info_xpath detail successfully")
        else:
            raise Exception("into message_comment_info_xpath detail failed")
        if d.xpath(message_comment_name_xpath).exists:
            print("into message_comment_name_xpath detail successfully")
        else:
            raise Exception("into message_comment_name_xpath detail failed")
        if d.xpath(message_comment_time_xpath).exists:
            print("into message_comment_time_xpath detail successfully")
        else:
            raise Exception("into message_comment_time_xpath detail failed")
        if d.xpath(message_comment_video_header_xpath).exists:
            print("into message_comment_video_header_xpath detail successfully")
        else:
            raise Exception("into message_comment_video_header_xpath detail failed")
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-粉丝
    """
    def check_message_fans(self, d):
        print("check_message_fans")
        d.xpath(message_to_fans_xpath).wait(timeout=3.0)
        d.xpath(message_to_fans_xpath).click()
        d.xpath(message_title_xpath).wait(timeout=3.0)
        title = d.xpath(message_title_xpath).get_text()
        assert title == "粉丝"
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-分享
    """

    def check_message_share(self, d):
        print("check_message_share")
        d.xpath(message_to_share_xpath).wait(timeout=3.0)
        d.xpath(message_to_share_xpath).click()
        d.xpath(message_title_xpath).wait(timeout=3.0)
        title = d.xpath(message_title_xpath).get_text()
        assert title == "分享"
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-系统消息
    """

    def check_message_system_notice(self, d):
        print("check_message_system_notice")
        d.xpath(message_to_system_notice_xpath).wait(timeout=3.0)
        d.xpath(message_to_system_notice_xpath).click()
        d.xpath(message_title_xpath).wait(timeout=3.0)
        title = d.xpath(message_title_xpath).get_text()
        assert title == "系统消息"
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-活动通知
    """

    def check_message_activity_notice(self, d):
        print("check_message_activity_notice")
        d.xpath(message_to_activity_notice_xpath).wait(timeout=3.0)
        d.xpath(message_to_activity_notice_xpath).click()
        d.xpath(message_title_xpath).wait(timeout=3.0)
        title = d.xpath(message_title_xpath).get_text()
        assert title == "活动通知"
        if d.xpath(message_activity_create_time_xpath).exists:
            print("into message_activity_create_time_xpath detail successfully")
        else:
            raise Exception("into message_activity_create_time_xpath detail failed")
        if d.xpath(message_activity_Img_xpath).exists:
            print("into message_activity_Img_xpath detail successfully")
        else:
            raise Exception("into message_activity_Img_xpath detail failed")
        if d.xpath(message_activity_notice_title_xpath).exists:
            print("into message_activity_notice_title_xpath detail successfully")
        else:
            raise Exception("into message_activity_notice_title_xpath detail failed")
        if d.xpath(message_activity_notice_content_xpath).exists:
            print("into message_activity_notice_content_xpath detail successfully")
        else:
            raise Exception("into message_activity_notice_content_xpath detail failed")
        if d.xpath(message_activity_to_detail_xpath).exists:
            print("into message_activity_to_detail_xpath detail successfully")
        else:
            raise Exception("into message_activity_to_detail_xpath detail failed")
        self.check_message_activity_notice_detail(d)
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-活动通知详情
    """

    def check_message_activity_notice_detail(self, d):
        print("check_message_activity_notice_detail")
        d.xpath(message_activity_to_detail_xpath).click()
        d.xpath(message_activity_detail_xpath).wait(timeout=3.0)
        if d.xpath(message_activity_detail_xpath).exists:
            print("into message_activity_detail_xpath detail successfully")
        else:
            raise Exception("into message_activity_detail_xpath detail failed")
        time.sleep(1)
        d.press("back")
        return self

    """
    查看消息-产品动态
    """

    def check_message_fresh_broadcast(self, d):
        print("check_message_fresh_broadcast")
        d.xpath(message_to_fresh_broadcast_xpath).wait(timeout=3.0)
        d.xpath(message_to_fresh_broadcast_xpath).click()
        d.xpath(message_title_xpath).wait(timeout=3.0)
        title = d.xpath(message_title_xpath).get_text()
        assert title == "产品动态"
        time.sleep(1)
        d.press("back")
        time.sleep(1)
        if d.xpath(message_to_fresh_broadcast_xpath).exists:
            d.press("back")

        return self